<template>
  <div class="app-container">
    <!-- 查询模块 -->
    <div class="formDiv">
      <el-form ref="form" :inline="true" label-width="130px">
        <el-row>
          <!-- <el-col :span="6">
            <el-form-item label="订单号">
              <el-input placeholder="请输入订单号"></el-input>
            </el-form-item>
          </el-col>-->
          <el-col :span="6">
            <el-form-item label="奖励时间">
              <el-date-picker
                type="daterange"
                value-format="yyyy-MM-dd"
                range-separator="-"
                start-placeholder="开始日期"
                end-placeholder="结束日期"
                :default-time="['00:00:00', '23:59:59']"
                v-model="time"
              ></el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="购买类型">
              <el-select v-model="params.type">
                <el-option
                  v-for="item in insureOptions"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label="奖励类型">
              <el-select v-model="params.awardType">
                <el-option
                  v-for="item in applyOptions"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-button style="margin-left:60px" type="primary" @click="searchFn">查询</el-button>
            <el-button
              type="primary"
              @click="excelEvent"
              v-if="permissionJson.indexOf('AdminUsersRewardTransProvider.lifeExport') !=-1"
            >导出</el-button>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- table -->
    <div class="table" v-loading="tableLoading">
      <el-table :data="tableData" style="width: 100%">
        <el-table-column
          type="index"
          label="序号"
          fixed="left"
          align="center"
          :index="table_index"
          width="50"
        ></el-table-column>
        <el-table-column prop="type" align="center" label="购买类型"></el-table-column>
        <el-table-column prop="orderSn" align="center" label="订单号"></el-table-column>
        <el-table-column prop="declarationUsername" align="center" label="报单手机号">
          <template slot-scope="scope">
            <div>{{scope.row.declarationUsername | phonereg }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="declarationRealname" align="center" label="报单姓名"></el-table-column>
        <el-table-column prop="amount" align="center" label="奖励金额"></el-table-column>
        <el-table-column prop="rewardUsername" align="center" label="奖励手机号">
          <template slot-scope="scope">
            <div>{{scope.row.rewardUsername | phonereg }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="rewardRealname" align="center" label="奖励姓名"></el-table-column>
        <el-table-column prop="awardType" align="center" label="奖励类型"></el-table-column>
        <el-table-column prop="intoTime" align="center" label="奖励时间"></el-table-column>
      </el-table>
    </div>
    <div class="pagesCon">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="params.pageNum"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="params.pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="page_totals"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import { getList, excelExport } from "@/api/financialOther";
import { exportfile } from "@/api/exporfile";

export default {
  name: "WDrewards",
  data() {
    return {
      tableLoading: true,
      tableData: [],
      time: [],
      permissionJson: JSON.parse(localStorage.getItem("permissionJson")),
      params: {
        intoTimeStart: null,
        intoTimeEnd: null,
        type: null,
        awardType: null,
        pageNum: 1,
        pageSize: 10
      },
      // page_sizes: [10, 30, 50, 100],
      page_totals: 60,
      //购买类型
      insureOptions: [
        { id: null, name: "全部" },
        { id: 4, name: "商品" },
        { id: 5, name: "生活美容" },
        { id: 6, name: "PLUS会员" }
      ],
      //奖励类型
      applyOptions: [
        { id: null, name: "全部" },
        { id: 1, name: "一级服务商奖励" },
        { id: 2, name: "二级服务商奖励" },
        { id: 3, name: "团队奖励" },
        { id: 4, name: "区域省奖励(老)" },
        { id: 5, name: "区域市奖励(老)" },
        { id: 6, name: "特殊奖励" },
        { id: 7, name: "省奖励（新）" },
        { id: 8, name: "大区域奖励" },
        { id: 9, name: "业绩二单奖励" },
        { id: 10, name: "团队二单奖励" },
        { id: 11, name: "业绩奖励（系统加减）" },
        { id: 12, name: "团队奖励（系统加减）" },
        { id: 13, name: "试用业绩奖励 " },
        { id: 14, name: "试用团队奖励 " },
        { id: 15, name: "试用大区域奖励 " },
        { id: 16, name: "会员分销奖励" }
      ]
    };
  },
  mounted() {
    this.getList(this.params);
  },
  methods: {
    table_index(index) {
      return (this.params.pageNum - 1) * this.params.pageSize + index + 1;
    },
    //获取分成明细列表
    getList(e) {
      const datas = e;
      getList(datas)
        .then(res => {
          // console.log(res);
          if (!res.data.code) {
            this.tableData = res.data.data.list;
            this.page_totals = res.data.data.count;
          } else {
            this.$message.error(res.data.msg);
          }
          this.tableLoading = false;
        })
        .catch(error => {
          this.$message.error(error);
          this.tableLoading = false;
        });
    },
    // 查询
    searchFn() {
      this.params.pageNum = 1;
      if (this.time != null) {
        if (this.time.length) {
          this.params.intoTimeStart = this.time[0];
          this.params.intoTimeEnd = this.time[1];
        }
      } else {
        this.params.intoTimeStart = null;
        this.params.intoTimeEnd = "";
      }
      // console.log(this.params)
      this.getList(this.params);
    },
    //导出
    excelEvent() {
      let datas = { ...this.params };
      delete datas.pageNum;
      delete datas.pageSize;
      excelExport(datas).then(res => {
        exportfile(res);
      });
    },
    // 改变页面条数
    handleSizeChange(val) {
      this.params.pageSize = val;
      this.getList(this.params);
    },
    // 选择页数
    handleCurrentChange(val) {
      this.params.pageNum = val;
      this.getList(this.params);
    }
  }
};
</script>
<style scoped>
/* 分页 */
.pagesCon {
  height: 40px;
  margin-top: 20px;
}
.pagesCon > div {
  float: right;
}
/* 表单样式修改 */
.el-range-editor--medium.el-input__inner {
  width: 236px;
}
</style>